<template>
    <div>
        <h2 style="word-wrap: break-word;text-align:center;">{{meetingFile.name}}</h2>
        <hr style="height:1.5px;border:none;border-top:1.5px solid #555555;"/>
        <el-button style="margin: 5% auto;display: block" type="primary" v-if="signInGo" @click="toSignIn">
            点击签到进入在线会议系统
        </el-button>
        <el-button style="margin: 5% auto;display: block" type="primary" v-if="signIn" @click="toSignIn">
            在线会议
        </el-button>
        <el-form :model="item">
            <el-form-item label="会议描述 ：">
                <span>关于{{item.description}}的会议</span>
            </el-form-item>
            <el-form-item label="签到开始时间 ：">
                <span v-if="_self.signStartTime !== ''">{{item.signStartTime}}</span>
            </el-form-item>
            <el-form-item label="会议开始时间 ：">
                <span v-if="_self.startTime !== ''">{{item.startTime}}</span>
            </el-form-item>
            <el-form-item label="会议结束时间 ：">
                <span v-if="_self.endTime !== ''">{{item.endTime}}</span>
            </el-form-item>
        </el-form>

        <el-table :data="meetingFileList"
                  v-show="this.fileids !== ''"
                  @cell-click="downloadFile">
            <el-table-column
                    prop="name"
                    label="文件列表">
            </el-table-column>
        </el-table>
        <el-dialog
                title="文件下载地址"
                :visible.sync="centerDialogVisible"
                width="90%">
            <span style="word-wrap: break-word;" id="compressFileUrl">{{meetingFile.compressFileUrl}}</span>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
                <el-button type="primary" @click="toCopy">复 制</el-button>
            </span>
        </el-dialog>
        <el-button v-if="meetingFile.compressFileUrl !== ''" style="margin:5% auto;display: block" type="primary"
                   @click="centerDialogVisible = true">点击查看并复制文件下载地址
        </el-button>
    </div>
</template>

<script>
    import util from 'assets/js/util.js'
    import conf from 'assets/js/conf.js'

    export default {
        data() {
            return {
                centerDialogVisible: false,
                signIn: false,
                signInGo: false,
                name: '',
                meetingFileList: [],
            }
        },
        props: [
            'meetingFile',
            'item',
            'fileids',
            'signState',
            'endTime',
        ],
        mounted() {
            this.meetingId = util.getUrlParam(document.location.href, 'meetingId');
            this.creditorId = util.getUrlParam(document.location.href, 'creditorId');

            const _self = this;
            util.ajax({
                url: '/file/getFileList',
                params: {eids: this.fileids},
                success: function (data) {
                    data.data.forEach(_file => _self.meetingFileList.push({
                        id: _file.id,
                        name: _file.name,
                        url: _file.url,
                    }));
                },
            });
            let myDate = new Date().getTime();
            //签到开始未结束
            if (myDate < _self.endTime || _self.endTime === '') {
                //没签到
                if (_self.signState === 0) {
                    this.signInGo = true
                } else {
                    //已签到
                    this.signInGo = false;
                    this.signIn = true;
                }
                //签到时间结束
            } else if (myDate >= _self.endTime && _self.endTime !== '') {
                this.signIn = true
            }
        },
        methods: {
            downloadFile: function (row, column, cell, event) {
                window.open(conf.baseUrl + '/file/get/' + row.id + '?type=1')
            },
            toSignIn: function () {
                const _self = this;
                let myDate = new Date().getTime();
                if (myDate < _self.endTime || _self.endTime === '') {
                    if (_self.signState === 0) {
                        util.ajax({
                            url: `/meeting/sign`,
                            params: {meetingId: util.getUrlParam(document.location.href, 'meetingId')},
                            success: function (data) {
                                if (data.status === 200) {
                                    _self.signIn = true;
                                    _self.toMeetingSystem(_self.meetingId, _self.creditorId)
                                }
                                else {
                                    alert(data.message);
                                }
                            },
                        });
                    } else {
                        _self.toMeetingSystem(_self.meetingId, _self.creditorId)
                    }
                }
                if (myDate >= _self.endTime && _self.endTime !== '') {
                    _self.toMeetingSystem(_self.meetingId, _self.creditorId)
                }
            },
            toMeetingSystem(meetingId, creditorId) {
                util.ajax({
                    url: '/channel/list',
                    params: {meetingId: util.getUrlParam(document.location.href, 'meetingId')},
                    success: function (data) {
                        if (data.data.type === 1) {
                            let watchList = [];
                            data.data.channel.content.forEach(_watch => watchList.push({
                                hlsPullUrl: _watch.hlsPullUrl,
                                httpPullUrl: _watch.httpPullUrl,
                                rtmpPullUrl: _watch.rtmpPullUrl,
                                dataSource: {type: "application/x-mpegURL", src: _watch.hlsPullUrl},
                                id: _watch.id,
                                name: _watch.name,
                            }));
                            window.location.href = '../meeting/meeting-system.html?' + 'meetingId=' + meetingId + '&creditorId=' + creditorId + '&hlsPullUrl=' + watchList[0].hlsPullUrl;
                        } else {
                            window.location.href = '../meeting/meeting-system.html?' + 'meetingId=' + meetingId + '&creditorId=' + creditorId;
                        }
                    },
                });
            },
            toCopy: function () {
                let Url = document.getElementById("compressFileUrl").innerText;
                let oInput = document.createElement('input');
                oInput.value = Url;
                document.body.appendChild(oInput);
                oInput.select(); // 选择对象
                document.execCommand("Copy"); // 执行浏览器复制命令
                oInput.className = 'oInput';
                oInput.style.display = 'none';
                alert('复制成功');
            },
        }
    }
</script>

<style>

</style>
